package com.zzp.sms.security.service;

import com.zzp.sms.security.domain.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 佐斯特勒
 * <p>
 *  用户服务类，这里使用本地方式
 * </p>
 * @version v1.0.0
 * @date 2020/1/13 13:52
 * @see  SysUserService
 **/
@Service
public class SysUserService {

    /**
     * 暂存用户的map集合
     */
    private static Map<String, SysUser> userMap = new HashMap<>();

    /**
     * 在当前的这个bean构造完之后，执行该代码
     */
    @PostConstruct
    public void init() {
        var sysUser = new SysUser();
        sysUser.setId(1);
        sysUser.setUsername("jack");
        sysUser.setPassword("$2a$10$ODIws5e9r1LvPAGJWogJjuJEaoVGDsTIJLW3udUQ2yjRy2pn/HDIG");
        var sysUserProcess = Arrays.asList("company:delete");
        sysUser.setProcess(sysUserProcess);
        /*
         * 第一个用户
         */
        var sysUser2 = new SysUser();
        sysUser2.setId(3);
        sysUser2.setUsername("smith");
        sysUser2.setPassword("$2a$10$ODIws5e9r1LvPAGJWogJjuJEaoVGDsTIJLW3udUQ2yjRy2pn/HDIG");
        var sysUser2Process = Arrays.asList("company:edit");
        sysUser2.setProcess(sysUser2Process);
        /*
         * 第二个用户
         */
        var user2 = new SysUser();
        user2.setId(2);
        user2.setUsername("13420530080");
        user2.setPassword("$2a$10$ODIws5e9r1LvPAGJWogJjuJEaoVGDsTIJLW3udUQ2yjRy2pn/HDIG");
        user2.setProcess(Arrays.asList("company:edit"));
        userMap.put("jack", sysUser);
        userMap.put("13420530080", user2);
        userMap.put("smith", sysUser2);
    }

    public SysUser getSysUserByUsernameOrPhoneNum(String usernameOrPhoneNum) {
        return userMap.get(usernameOrPhoneNum);
    }
}
